#include <sourcemod>
#include <sdktools>
#include <cstrike>


/**************************************************************
 변수 (VARIABLES)
**************************************************************/
//new health[MAXPLAYERS+1];
//new helpme[MAXPLAYERS+1];
new bool:g_ActiWeaponWB4[MAXPLAYERS + 1] = false;
new g_iPlayerMoney;
new g_FireOrange;
new g_HaloSprite;
new g_ExplosionSprite;


/**************************************************************
 플러그인 정보 (PLUGIN INFORMATION)
**************************************************************/
public Plugin:myinfo = {
	
	name = "Rabi's upgrade shop",
	author = "라비",
	description = "CS:S",
	version = "0.1",
	url = "http://cafe.naver.com/vunit"
};


/**************************************************************
 주요 동작 함수 (HEADER FUNCTIONS)
**************************************************************/
public OnPluginStart()
{
	// 콘솔명령어등록("say", 콜백이름);
	RegConsoleCmd("say", SayEvent);
	
	// 명령 추가(콜백이름, "키");
	RegConsoleCmd("autobuy", Function_CallGunShop);

	// 게임이벤트훅("이벤트이름", 콜백이름);
	HookEvent("round_freeze_end", Event_OnRoundFreezeEnd);
	HookEvent("round_end", Event_OnRoundEnd);
	HookEvent("weapon_fire", Event_OnWeaponFire);
	
	// 돈 오프셋 찾아서 등록.
	g_iPlayerMoney = FindSendPropInfo("CCSPlayer", "m_iAccount");
	if (g_iPlayerMoney == -1)
	{
		SetFailState("[RB Shop] Cannot find CCSPlayer::m_iAccount");
	}
	
	// 프리캐시
	g_FireOrange = PrecacheModel("materials/sprites/fire2.vmt");
	g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt");
	g_ExplosionSprite = PrecacheModel("materials/sprites/sprite_fire01.vmt");
	PrecacheSound("ambient/explosions/explode_8.wav", true);
}

public Action:SayEvent(Client, args)
{
	decl String:says[192];
	GetCmdArgString(says, sizeof(says));
	ReplaceString(says, sizeof(says), "\"", "");
	
	if(StrEqual(says, "!특수상점", false))
	{
		if(IsPlayerAlive(Client))
		{
			if(GetClientHealth(Client) <= 300) 
			{
				Command_Gunshop(Client);
			}
			else
			{
				PrintToChat(Client, "\x05[라비상점] \x01- 인간만 가능합니다.");
			}
		}
		else
		{
			PrintToChat(Client, "\x05[라비상점] \x01- 죽은 사람은 이용할 수 없습니다.");
		}
	}
}

public Action:Function_CallGunShop(Client, Args)
{
	Command_Gunshop(Client);
}

public Action:Event_OnRoundFreezeEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
	/*
	// 클라이언트 전체를 구해서 팝업 띄우기
	// x = 클라이언트 인덱스라고 인식.
	for (new x = 1; x <= MaxClients; x++)
	{
		// 플레이어가 게임에 있고, 살아있으면 합격
		if (IsClientInGame(x) && IsPlayerAlive(x))
		{
			Command_Gunshop(x);
		}
	}
	*/
}

public Action:Event_OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
	for (new i = 1; i <= MaxClients; i++)
	{
		g_ActiWeaponWB4[i] = false;
	}
}

public Action:Event_OnWeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
	new Client = GetClientOfUserId(GetEventInt(event, "userid"));
	static String:g_SWeapon[32];
	
	GetEventString(event, "weapon", g_SWeapon, sizeof(g_SWeapon));
	
	if (StrEqual(g_SWeapon, "xm1014") && g_ActiWeaponWB4[Client]) // 구체화 작업이 필요하다. (참고 - Shot Between Reloading, Double Shot Check, Ammo Check)
	{
		Function_Boom(Client);
	}
}


/**************************************************************
 일반 함수 (GENERAL FUNCTIONS)
**************************************************************/
public Command_Gunshop(Client)
{
	new Handle:Panel = CreatePanel();
	SetPanelTitle(Panel, "[Rabi's Special Shop]");
	DrawPanelText(Panel, " ");
	DrawPanelItem(Panel, "[Trap Mine]");
	DrawPanelItem(Panel, "[Special Bullet]");
	DrawPanelItem(Panel, "[Special Grenade]");
	DrawPanelItem(Panel, "[Special Gun]");
	DrawPanelItem(Panel, "[Ammo]");
	DrawPanelItem(Panel, "[Special Random Gun]");
	DrawPanelText(Panel, " ");
	
	SetPanelCurrentKey(Panel, 10);
	DrawPanelItem(Panel, "나가기");
 	
	SendPanelToClient(Panel, Client, Menu_Gunshop, 30);
	
	CloseHandle(Panel);
}

public Command_BL(Client)
{
	new Handle:Panel2 = CreatePanel();
	SetPanelTitle(Panel2, "[Rabi's Bullet Shop]");
	DrawPanelText(Panel2, " ");
	DrawPanelItem(Panel2, "[소이탄]");
	DrawPanelItem(Panel2, "[백린탄]");
	DrawPanelItem(Panel2, "[LO탄]");
	DrawPanelItem(Panel2, "[열화우라늄탄]");
	DrawPanelItem(Panel2, "[풀메탈재킷]");
	DrawPanelItem(Panel2, "[할로우포인트]");
	DrawPanelItem(Panel2, "[50BMG]");
	DrawPanelText(Panel2, " ");
	
	SetPanelCurrentKey(Panel2, 10);
	DrawPanelItem(Panel2, "나가기");
 	
	SendPanelToClient(Panel2, Client, Menu_BL, 30);
	
	CloseHandle(Panel2);
}

public Menu_Gunshop(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			//Command_MN(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_BL(Client);
		}
		
		if(Parameter2 == 3)
		{
			//Command_GR(Client);
		}
		
		if(Parameter2 == 4)
		{
			//Command_SG(Client);
		}
		
		if(Parameter2 == 5)
		{
			//Command_AM(Client);
		}
		
		if(Parameter2 == 6)
		{
			Command_Rand(Client);
		}
	}
	
	CloseHandle(Panel);
}

public Menu_BL(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel2 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			Command_B1(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_B2(Client);
		}
		
		if(Parameter2 == 3)
		{
			Command_B3(Client);
		}
		
		if(Parameter2 == 4)
		{
			Command_B4(Client);
		}
		
		if(Parameter2 == 5)
		{
			Command_B5(Client);
		}
		
		if(Parameter2 == 6)
		{
			Command_B6(Client);
		}

		if(Parameter2 == 7)
		{
			Command_B7(Client);
		}
	}
	
	CloseHandle(Panel2);
}

/**************************************************************
 Bullet Shop
**************************************************************/

// 소이탄
public Command_B1(Client)
{
	new Handle:Panel3 = CreatePanel();
	
	SetPanelTitle(Panel3,"소이탄. 적을 맞출시 적이 불탄다.");
	DrawPanelText(Panel3, " ");
	DrawPanelItem(Panel3, "구입");
	DrawPanelItem(Panel3, "뒤로가기 ");
	
	SetPanelCurrentKey(Panel3, 10);
	DrawPanelItem(Panel3, "나가기");
	SendPanelToClient(Panel3, Client, Menu_B1, 30);
	
	CloseHandle(Panel3);
}

public Menu_B1(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel3 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			// Rand(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_Gunshop(Client);
		}
	}
	
	CloseHandle(Panel3);
}

// 백린탄
public Command_B2(Client)
{
	new Handle:Panel4 = CreatePanel();
	
	SetPanelTitle(Panel4,"백린탄. 적을 맞출시 적을 포함한 주변 적을 태운다.");
	DrawPanelText(Panel4, " ");
	DrawPanelItem(Panel4, "구입");
	DrawPanelItem(Panel4, "뒤로가기 ");
	
	SetPanelCurrentKey(Panel4, 10);
	DrawPanelItem(Panel4, "나가기");
	 	
	SendPanelToClient(Panel4, Client, Menu_B2, 30);
	
	CloseHandle(Panel4);
}

public Menu_B2(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel4 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			// Rand(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_Gunshop(Client);
		}
	}
	
	CloseHandle(Panel4);
}

// LO탄
public Command_B3(Client)
{
	new Handle:Panel5 = CreatePanel();
	
	SetPanelTitle(Panel5,"LO탄. 해석하자면 리퀴드 옥시젠. 냉동탄이다.");
	DrawPanelText(Panel5, " ");
	DrawPanelItem(Panel5, "구입");
	DrawPanelItem(Panel5, "뒤로가기 ");
	
	SetPanelCurrentKey(Panel5, 10);
	DrawPanelItem(Panel5, "나가기");
	 	
	SendPanelToClient(Panel5, Client, Menu_B3, 30);
	
	CloseHandle(Panel5);
}

public Menu_B3(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel5 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			// Rand(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_Gunshop(Client);
		}
	}
	
	CloseHandle(Panel5);
}

// 열화우라늄탄
public Command_B4 (Client)
{
	new Handle:Panel6 = CreatePanel();
	
	SetPanelTitle(Panel6,"열화 우라늄탄. 폭파효과가 추가된다.");
	DrawPanelText(Panel6, " ");
	DrawPanelItem(Panel6, "구입");
	DrawPanelItem(Panel6, "뒤로가기 ");
	SetPanelCurrentKey(Panel6, 10);
	DrawPanelItem(Panel6, "나가기");
	 	
	SendPanelToClient(Panel6, Client, Menu_B4, 30);
	
	CloseHandle(Panel6);
}

public Menu_B4(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel6 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			g_ActiWeaponWB4[Client] = true;
		}
		
		if(Parameter2 == 2)
		{
			Command_Gunshop(Client);
		}
	}
	
	CloseHandle(Panel6);
}

// 풀메탈재킷
public Command_B5(Client)
{
	new Handle:Panel7 = CreatePanel();
	
	SetPanelTitle(Panel7,"풀 메탈 재킷. 데미지가 향상된다.");
	DrawPanelText(Panel7, " ");
	DrawPanelItem(Panel7, "구입");
	DrawPanelItem(Panel7, "뒤로가기 ");
	
	SetPanelCurrentKey(Panel7, 10);
	DrawPanelItem(Panel7, "나가기");
	 	
	SendPanelToClient(Panel7, Client, Menu_B5, 30);
	
	CloseHandle(Panel7);
}

public Menu_B5(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel7 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			// Rand(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_Gunshop(Client);
		}
	}
	
	CloseHandle(Panel7);
}

// 할로우포인트
public Command_B6(Client)
{
	new Handle:Panel8 = CreatePanel();
	
	SetPanelTitle(Panel8,"할로우 포인트탄. FMJ보다 데미지 향상이 크다.");
	DrawPanelText(Panel8, " ");
	DrawPanelItem(Panel8, "구입");
	DrawPanelItem(Panel8, "뒤로가기 ");
	
	SetPanelCurrentKey(Panel8, 10);
	DrawPanelItem(Panel8, "나가기");
	 	
	SendPanelToClient(Panel8, Client, Menu_B6, 30);
	
	CloseHandle(Panel8);
}

public Menu_B6(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel8 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			// Rand(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_Gunshop(Client);
		}
	}
	
	CloseHandle(Panel8);
}

// 50BMG
public Command_B7(Client)
{
	new Handle:Panel9 = CreatePanel();
	
	SetPanelTitle(Panel9,"저격총용 50구경탄. 저격총만 사용가능하다.");
	DrawPanelText(Panel9, " ");
	DrawPanelItem(Panel9, "구입");
	DrawPanelItem(Panel9, "뒤로가기 ");
	
	SetPanelCurrentKey(Panel9, 10);
	DrawPanelItem(Panel9, "나가기");
	 	
	SendPanelToClient(Panel9, Client, Menu_B7, 30);
	
	CloseHandle(Panel9);
}

public Menu_B7(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel9 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			// Rand(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_Gunshop(Client);
		}
	}
	
	CloseHandle(Panel9);
}

// 열화우라늄탄 작동 함수
public Action:Function_Boom(Client)
{
	new g_Explosion = CreateEntityByName("env_explosion");
	new g_HaloColor[4] = {188, 220, 255, 200};
	new Float:EyeVec[3];
	
	GetEyePosition(Client, EyeVec);
	
	DispatchKeyValueVector(g_Explosion, "Origin", EyeVec);
	DispatchKeyValue(g_Explosion,"iMagnitude", "100");
	DispatchKeyValue(g_Explosion,"iRadiusOverride", "0");
  	DispatchSpawn(g_Explosion);
	AcceptEntityInput(g_Explosion, "Explode");
	AcceptEntityInput(g_Explosion, "Kill");
	
	EmitSoundToAll("ambient/explosions/explode_8.wav", SOUND_FROM_WORLD, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, SNDVOL_NORMAL, SNDPITCH_NORMAL, -1, EyeVec, NULL_VECTOR, true, 0.0);
	
	TE_SetupExplosion(EyeVec, g_ExplosionSprite, 10.0, 1, 0, 600, 5000);
	TE_SendToAll();
	TE_SetupBeamRingPoint(EyeVec, 10.0, 500.0, g_FireOrange, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, g_HaloColor, 10, 0);
  	TE_SendToAll();
}

/**************************************************************
 도박 관련
**************************************************************/
public Command_Rand(Client)
{
	new Handle:Panel10 = CreatePanel();

	SetPanelTitle(Panel10, "도박메뉴. 특수총을 저렴하게 뽑을수 있습니다.");
	DrawPanelText(Panel10, " ");
	DrawPanelItem(Panel10, "1. 지르기 ");
	DrawPanelItem(Panel10, "2. 뒤로가기 ");
	
	SetPanelCurrentKey(Panel10, 10);
	DrawPanelItem(Panel10, "나가기");
 	
	SendPanelToClient(Panel10, Client, Menu_Rand, 30);
	
	CloseHandle(Panel10);
}

public Menu_Rand(Handle:Menu, MenuAction:Click, Parameter1, Parameter2)
{
	new Handle:Panel10 = CreatePanel();
	new Client = Parameter1;

	if(Click == MenuAction_Select)
	{
		if(GetPlayerWeaponSlot(Client, 0) != -1) RemovePlayerItem(Client, GetPlayerWeaponSlot(Client, 0));
		
		if(Parameter2 == 1)
		{
			Rand(Client);
		}
		
		if(Parameter2 == 2)
		{
			Command_Gunshop(Client);
		}
	}
	
	CloseHandle(Panel10);
}

public Rand(Client)
{
	new Bo = GetRandomInt(1, 5);
	
	new Money = Rabi_GetClientCash(Client);
	
	if (Money >= 10000)
	{
		if (Bo == 1)
		{
			GivePlayerItem(Client, "weapon_glock");
			PrintToChat(Client, "\x05[라비상점] \x01- Glock18 [연사모드.무한탄창] 당첨");
			Rabi_SetClientCash(Client, Money - 10000);
			Command_Gunshop(Client);
		}			
		
		else if (Bo == 2)
		{
			GivePlayerItem(Client, "weapon_awp");
			PrintToChat(Client, "\x05[라비상점] \x01- AW50 [데미지 5배] 당첨");
			Rabi_SetClientCash(Client, Money - 10000);
			Command_Gunshop(Client);
		}			
		
		else if (Bo == 3)
		{
			GivePlayerItem(Client, "weapon_m249");
			PrintToChat(Client, "\x05[라비상점] \x01- M249 터렛모드 [연사속도 +50%.무한탄창.이동속도 -70%] 당첨");
			Rabi_SetClientCash(Client, Money - 10000);
			Command_Gunshop(Client);
		}
		
		else if (Bo == 4)
		{
			GivePlayerItem(Client, "weapon_ump45");
			PrintToChat(Client, "\x05[라비상점] \x01- UMP45 개량형 [연사속도 50%.데미지 2배] 당첨");
			Rabi_SetClientCash(Client, Money - 10000);
			Command_Gunshop(Client);
		}	
		
		else if (Bo == 5)
		{
			GivePlayerItem(Client, "");
			PrintToChat(Client, "\x05[라비상점] \x01- 꽝. 다음기회에..");
			Rabi_SetClientCash(Client, Money - 10000);
			Command_Gunshop(Client);
		}
	}
	
	else PrintToChat(Client, "\x05[라비상점] \x01- 돈이 부족합니다.");
}


/**************************************************************
 참고 함수 (STOCK FUNCTIONS)
**************************************************************/
/**
 * 체크모듈; 클라이언트가 살아있는지 확인합니다.
 *
 * @param client		클라이언트 인덱스
 */
public bool:AliveCheck(Client)
{
	if(Client > 0 && Client <= MaxClients)
	{
		if(IsClientConnected(Client) == true)
		{
			if(IsClientInGame(Client) == true)
			{
				if(IsPlayerAlive(Client) == true)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{	
				return false;	
			}
		}
		else
		{		
			return false;		
		}
	}
	else
	{		
		return false;		
	}
}

/**
 * 계정모듈; 클라이언트의 현금이 얼마인지 획득합니다.
 *
 * @param client		클라이언트 인덱스
 */
stock Rabi_GetClientCash(Client)
{
	// 클라이언트 현금을 획득.
	return GetEntData(Client, g_iPlayerMoney, 4);
}

/**
 * 계정 모듈; 클라이언트의 돈을 특정수치로 지정합니다.
 *
 * @param client	클라이언트 인덱스
 * @param value		지정할 값
 */
stock Rabi_SetClientCash(Client, value)
{
	if (value < 0)
	{
		value = 0;
	}
	
	// 클라이언트의 현금을 특정수치로 설정.
	SetEntData(Client, g_iPlayerMoney, value, 4);
}

/**
 * 추적모듈; 클라이언트의 시점 좌표를 구합니다.
 *
 * @param client		클라이언트 인덱스
 * @param array		클라이언트 좌표
 */
stock GetEyePosition(Client, Float:array[3])
{
	new Float:start[3], Float:end[3], Float:angle[3];
	
	GetClientEyePosition(Client, start);
	GetClientEyeAngles(Client, angle);
	
	GetAngleVectors(angle, end, NULL_VECTOR, NULL_VECTOR);
	
	NormalizeVector(end, end);
	
	TR_TraceRayFilter(start, angle, MASK_PLAYERSOLID, RayType_Infinite, GEP_TEF, Client);
	if (TR_DidHit(INVALID_HANDLE))
	{
		TR_GetEndPosition(end, INVALID_HANDLE);
		array = end;
	}
}

public bool:GEP_TEF(entity, mask, any:data)
{
	if (entity == data)
	{
		return false;
	}
	return true;
}
////////////// 냉동탄 //////////////////////////// 
//new Handle:sm_freeze_awp_onoroff;
//new Handle:sm_freeze_awp_probability;
//new Handle:sm_freeze_awp_time;
//new Handle:sm_freeze_scout_onoroff;
//new Handle:sm_freeze_scout_probability;
//new Handle:sm_freeze_scout_time;
//new g_FreezeSerial[MAXPLAYERS+1] = { 0, ... };
//new g_FreezeTime[MAXPLAYERS+1] = { 0, ... };
//#define SOUND_FREEZE	"physics/glass/glass_impact_bullet4.wav"
//new g_Serial_Gen = 0;
//new g_GlowSprite        = -1;
//new g_HaloSprite        = -1;
//#define DEFAULT_TIMER_FLAGS TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE
//public OnPluginStart() {
	//CreateConVar("sm_FreezeSnipeGun_version", PLUGIN_VERSION, "Made By FoxBrother", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);

	//sm_freeze_awp_onoroff = CreateConVar("sm_freeze_awp_onoroff", "1", "(AWP)얼음총 사용 설정/0 = 사용안함, 1 = 사용함");
	//sm_freeze_awp_probability = CreateConVar("sm_freeze_awp_probability", "2", "(AWP)얼릴 확률 설정/높을수록 확율은 줄어듬");
	//sm_freeze_awp_time = CreateConVar("sm_freeze_awp_time", "5", "(AWP)얼릴 시간 설정/초단위");

	//sm_freeze_scout_onoroff = CreateConVar("sm_freeze_scout_onoroff", "1", "(스카웃)얼음총 사용 설정/0 = 사용안함, 1 = 사용함");
	//sm_freeze_scout_probability = CreateConVar("sm_freeze_scout_probability", "3", "(스카웃)얼릴 확률 설정/높을수록 확율은 줄어듬");
	//sm_freeze_scout_time = CreateConVar("sm_freeze_scout_time", "5", "(스카웃)얼릴 시간 설정/초단위");

	//HookEvent("player_hurt", Event_Damage);
}
//public OnMapStart() {
	g_GlowSprite = PrecacheModel("sprites/blueglow2.vmt");
	g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt");
}
//public Action:Event_Damage(Handle:Damage_Event, const String:Damage_Name[], bool:Damage_Broadcast) {
	new Client = GetClientOfUserId(GetEventInt(Damage_Event, "userid"));
	new Attacker = GetClientOfUserId(GetEventInt(Damage_Event, "Attacker"));
	new String:Weapon_Name[32];
	GetClientWeapon(Attacker, Weapon_Name, 32);
	if(StrEqual(Weapon_Name, "weapon_awp", false)) {
		if(GetConVarInt(sm_freeze_awp_onoroff) == 1) {
			new AWPProbability = GetConVarInt(sm_freeze_awp_probability);
			new AWPRollD = GetRandomInt(1, AWPProbability);
			if(AWPRollD == 1) {
				FreezeClient(Client, GetConVarInt(sm_freeze_awp_time));
			}
		}
	} else if(StrEqual(Weapon_Name, "weapon_scout", false)) {
		if(GetConVarInt(sm_freeze_scout_onoroff) == 1) {
			new ScoutProbability = GetConVarInt(sm_freeze_scout_probability);
			new ScoutRollD = GetRandomInt(1, ScoutProbability);
			if(ScoutRollD == 1) {
				FreezeClient(Client, GetConVarInt(sm_freeze_scout_time));
			}
		}
	}
}
//FreezeClient(client, time) {
	if (g_FreezeSerial[client] != 0) {
		UnfreezeClient(client);
		return;
	}
	SetEntityMoveType(client, MOVETYPE_NONE);
	SetEntityRenderColor(client, 0, 128, 255, 192);
	new Float:vec[3];
	GetClientEyePosition(client, vec);
	EmitAmbientSound(SOUND_FREEZE, vec, client, SNDLEVEL_RAIDSIREN);
	g_FreezeTime[client] = time;
	g_FreezeSerial[client] = ++ g_Serial_Gen;
	CreateTimer(1.0, Timer_Freeze, client | (g_Serial_Gen << 7), DEFAULT_TIMER_FLAGS);
}
//UnfreezeClient(client) {
	g_FreezeSerial[client] = 0;
	g_FreezeTime[client] = 0;
	if (IsClientInGame(client)) {
		new Float:vec[3];
		GetClientAbsOrigin(client, vec);
		vec[2] += 10;	
		GetClientEyePosition(client, vec);
		EmitAmbientSound(SOUND_FREEZE, vec, client, SNDLEVEL_RAIDSIREN);
		SetEntityMoveType(client, MOVETYPE_WALK);
		SetEntityRenderColor(client, 255, 255, 255, 255);
	}
}
//public Action:Timer_Freeze(Handle:timer, any:value) {
	new client = value & 0x7f;
	new serial = value >> 7;
	if (!IsClientInGame(client)
		|| !IsPlayerAlive(client)
		|| g_FreezeSerial[client] != serial) {
		UnfreezeClient(client);
		return Plugin_Stop;
	}
	if (g_FreezeTime[client] == 0) {
		UnfreezeClient(client);
		return Plugin_Stop;
	}
	g_FreezeTime[client]--;
	SetEntityMoveType(client, MOVETYPE_NONE);
	SetEntityRenderColor(client, 0, 128, 255, 135);
	new Float:vec[3];
	GetClientAbsOrigin(client, vec);
	vec[2] += 10;

	if (g_GlowSprite > -1) {
		TE_SetupGlowSprite(vec, g_GlowSprite, 0.95, 1.5, 50);
	} else {
		TE_SetupGlowSprite(vec, g_HaloSprite, 0.95, 1.5, 50);
	}
	TE_SendToAll();
	return Plugin_Continue;
}